'use strict';

const BaseService = require('./base');
const modelName = 'Model';
const { Op } = require('sequelize');
class RouterService extends BaseService {
  constructor(ctx) {
    super(ctx, modelName);
  }

  async userList(userId) {
    // 获取当前用户
    const user = await this.ctx.model.User.findOne({
      where: {
        id: userId
      },
      raw: true
    })
    console.log('user', user)
    if (!user) {
      throw new Error('用户不存在');
    }
    let modeList = user.model_list || []
    if (!modeList.length) {
      return []
    }
    console.log('modeList',modeList)
    return await this.ctx.model.Model.findAll({
      where: {
        model: {
          [Op.in]: modeList
        }
      },
    })
  }
}


module.exports = RouterService;
